﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using TFXK.Model;
using TFXK.BLL;
using TFXK.Common;
using log4net;

public partial class admin_OrderManage_Action : BasePage
{
    private static readonly ILog log = LogManager.GetLogger(typeof(admin_OrderManage_Action));
    private static readonly OrdersBLL bll = new OrdersBLL();
    private static readonly CategoryBLL bllCategory = new CategoryBLL();
    private static readonly CustomsBLL bllCustoms = new CustomsBLL();
    private static readonly HotelBLL bllHotel = new HotelBLL();
    private static readonly TravelLinesBLL bllTravelLines = new TravelLinesBLL();

    #region 加载
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                InitAction();
            }
        }
        catch (Exception ex)
        {
            log.Error(ex.Message);
        }

    }
    #endregion

    #region 绑定动作
    private void InitAction()
    {
        if (Request.QueryString["id"] != null)
        {
            int id = int.Parse(Request.QueryString["id"].ToString());
            InitData(id);
        }
        else
        {
            Response.Redirect("Default.aspx", false);
        }

    }
    #endregion

    #region 绑定
    private void InitData(int id)
    {
        Orders model = bll.GetModel(id);
        if (model != null)
        {
            lblCreateDate.Text = model.createDate + "";
            lblOrderDate.Text = model.orderDate + "";
            lblOrderNum.Text = model.orderNum + "";
            lblSex.Text = model.userSex ==0 ?"男":"女";
            if (model.orderType == 0) {
                lblTypeName.Text = "酒店预定";
            }
            else if (model.orderType == 1)
            {
                lblTypeName.Text = "线路预定";
            }
            else {
                lblTypeName.Text = "DIY信息";
            }
            try
            {
                if (model.orderType == 0)
                {
                    hlkOrderLink.Text = bllHotel.GetModel(model.parentID.Value).title;
                    hlkOrderLink.NavigateUrl = "../../HotelInfo.aspx?Key=" + model.parentID;
                }
                else if (model.orderType == 1)
                {
                    hlkOrderLink.Text = bllTravelLines.GetModel(model.parentID.Value).title;
                    hlkOrderLink.NavigateUrl = "../../LineInfo.aspx?Key=" + model.parentID;
                }
            }
            catch { }


            try
            {
                this.hlkOrderUser.Text = bllCustoms.GetModel(model.customID.Value).trueName;
                hlkOrderUser.NavigateUrl = "../CustomManage/Action.aspx?id=" + model.customID;
            }
            catch { }


            lblUserName.Text = model.userName;
            lblContent.Text = model.orderDes;
            ddlState.SelectedIndex = model.orderState.Value;
        }
    }
    #endregion

    #region 添加/修改
    protected void ibtnAdd_Click(object sender, EventArgs e)
    {
        //验证代码
        try
        {
          int id =0;
            int stateid =0;
            try
            {
               id = int.Parse(Request.QueryString["id"].ToString());
            }
            catch {}
            try
            {
                stateid = ddlState.SelectedIndex;
            }
            catch { }

            // 防止网页重复提交
            if (this.CheckRefreshed1.isRefreshed == false)
            {
                Modify(id,stateid);
            }
        }
        catch (Exception ex)
        {
            log.Error(ex.Message);
            Msg.Show("网络错误!原因:" + ex.Message);
        }
    }
    #endregion


    #region 修改
    private void Modify(int id,int stateid)
    {
        bll.Update(id,stateid);
        Msg.ShowAndRedirect("处理信息成功!", "Default.aspx");
    }
    #endregion

    #region 返回
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx", false);
    }
    #endregion

}
